package com.gc.jbnfgen.demo;

import com.gc.sql.test.*;

/**
 * <pre>
 * run:
 * expr = 123 - 321
 * expr = a + b
 * expr = ( a + b )
 * expr = ( a + b ) + ( a + b )
 * expr = ( a + b ) + ( a + b ) as a1
 * BUILD SUCCESSFUL (total time: 0 seconds)
 * </pre>
 * @author dmitry.mamonov
 */
public class Demo {
    public static void main(String[] args) {
        Expression a = Expression.create(Value.create(Identifier.create(new Name("a"))));
        Expression b = Expression.create(Value.create(Identifier.create(new Name("b"))));

        Expression aPlusB = Expression.create(OperationInExpression.builder()
                .left(a)
                .operation(Operation.createPlus())
                .right(b));
        Expression withBrackets = Expression.create(NestedExpression.builder()
                .leftBracket()
                .expression(aPlusB)
                .rightBracket());
        Expression naPlusNb = Expression.create(OperationInExpression.builder()
                .left(withBrackets)
                .operation(Operation.createPlus())
                .right(withBrackets));

        Expression expr = Expression.create(
                OperationInExpression.builder()
                .left(Expression.create(Value.create(new Numeric(123))))
                .operation(Operation.createMinus())
                .right(Expression.create(Value.create(new Numeric(321)))));
        ExpressionWithAlias exprA = ExpressionWithAlias.builder()
                .expression(naPlusNb)
                .alias(Alias.create(AliasName.builder()
                    .aliasConstant(AliasConstant.createAs())
                    .name(new Name("a1"))));

        System.out.println("expr = "+expr);
        System.out.println("expr = "+aPlusB);
        System.out.println("expr = "+withBrackets);
        System.out.println("expr = "+naPlusNb);
        System.out.println("expr = "+exprA);
    }
}
